ateom: remove the ateom directory on graceful shutdown - #1678
Merged
Jeff Luo (JeffLuoo) merged 3 commits intoSep 19, 2026
Merged
Conversation
Tim Bai (baizhenyu)
force-pushed
the
ateom-dir-self-cleanup
branch
from
September 16, 2026 18:36
e4a18ca to
8be659b
Compare
Nothing removes ateoms/<podUID>/ when a worker pod goes away, so every pool rollout leaks one directory per replaced worker onto the node -- and since the stats sweep enumerates that directory as its discovery registry, each leak costs a dial+probe per sweep forever (agent-substrate#1677). A defer after the MkdirAll covers the exits that dominate that growth: rollouts terminate gracefully, so the SIGTERM path (drain, GracefulStop, Serve returns, do returns) runs it, as do error returns during boot. Safe against a same-pod container restart because kubelet does not start the replacement container until this process -- and so this defer -- has exited. Ungraceful exits (SIGKILL, OOM, node crash) skip defers by nature; the atelet-side janitor proposed in agent-substrate#1677 is the backstop for those, and this change shrinks its caseload to them. Part of agent-substrate#1677.
Tim Bai (baizhenyu)
force-pushed
the
ateom-dir-self-cleanup
branch
from
September 16, 2026 18:37
8be659b to
ea4dfa1
Compare
Tim Bai (baizhenyu)
requested review from
Benjamin Elder (BenTheElder),
Jeff Luo (JeffLuoo),
Da Huang (git286) and
Zoe Zhao (zoez7)
September 16, 2026 18:46
This was referenced Sep 16, 2026
Jeff Luo (JeffLuoo)
requested changes
Sep 17, 2026
An empty or path-shaped pod UID was previously harmless -- MkdirAll
just created a wrong path -- but the shutdown RemoveAll turned it
destructive: AteomPath("") is AteomsDir() itself, so a misconfigured
ateom would delete every ateom's socket directory on the node. Fail
fast at boot instead, with the validator the atelet RPC boundary
already uses.
Jeff Luo (JeffLuoo)
previously approved these changes
Sep 17, 2026
os.Exit(1) on a Serve failure skipped every defer in do(), including the tracer and meter shutdowns and now the ateom directory removal. Return the error the way ateom-microvm does; main logs it and exits.
Jeff Luo (JeffLuoo)
enabled auto-merge
September 18, 2026 18:52
Benjamin Elder (BenTheElder)
approved these changes
Sep 18, 2026
Merged
via the queue into
agent-substrate:main
with commit Sep 19, 2026
27bf344
14 of 15 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #1677 — the graceful-shutdown half; the atelet-side janitor for ungraceful exits is tracked there.
Nothing removes
ateoms/<podUID>/when a worker pod goes away, so every pool rollout leaks one directory (holding a deadateom.sock) per replaced worker — and since the stats sweep enumerates that directory as its discovery registry (#961), each leak costs a dial+probe per sweep, forever.Change
A
defer os.RemoveAll(ateomDir)in both runtime mains, registered right after theMkdirAllthat creates the directory. ~7 lines each plus the comment carrying the safety argument.Why this is safe:
MkdirAll.GracefulStops,Servereturns,doreturns — the defer runs after the listener is already closed, so nothing can be dialing the socket it removes.Listenalso run the defer; the pod restarts and re-creates the directory. Harmless.What it deliberately does not cover: SIGKILL after the grace period, OOM kills, node crashes — defers don't run there by nature. That residue is the janitor's job (#1677); this change shrinks the janitor's caseload to exactly those, since rollouts — the dominant growth driver — terminate gracefully.
Testing
Both runtime mains are untested boot plumbing (no unit seam exists for
do()); verified by linux builds and test-compiles of both packages.Live-verified on the ate-dev GKE cluster (gVisor pool; the micro-VM change is the identical lines):
445af5aa…) leaked its directory on termination, reproducing the bug side-by-side with the fix.5618282c…): its directory was removed on shutdown, while the pre-change pod's leaked directory remained in the same census — before/after behavior on the same node, same listing.